﻿using System.Windows;
using System.Windows.Controls;

namespace Xioa_UI.Controls;

public class XioaExpander : Expander
{
    static XioaExpander()
    {
        ElementBase.DefaultStyle<XioaExpander>(DefaultStyleKeyProperty);
    }
    
    
    #region Private属性
    private FrameworkElement? _partRoot;
    #endregion

    #region Override方法
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        this._partRoot = this.GetTemplateChild("PART_Root") as FrameworkElement;
        if (this._partRoot != null)
        {
            VisualStateManager.GoToElementState(this._partRoot, this.IsExpanded ? "Storyboard_Expanded" : "Storyboard_Collapsed", true);
        }
    }
    protected override void OnCollapsed()
    {
        base.OnCollapsed();
        if (this._partRoot != null)
        {
            VisualStateManager.GoToElementState(this._partRoot, "Storyboard_Collapsed", true);
        }
    }
    protected override void OnExpanded()
    {
        base.OnExpanded();
        if (this._partRoot != null)
        {
            VisualStateManager.GoToElementState(this._partRoot, "Storyboard_Expanded" , true);
        }
    }
    #endregion

}